package io.sage.modules.basics.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.sage.modules.basics.dao.BGoodsUnitMapper;
import io.sage.modules.basics.entity.BGoodsUnit;
import io.sage.modules.basics.service.BGoodsUnitService;


@Service("goodsUnitService")
public class BGoodsUnitServiceImpl implements BGoodsUnitService {
	
	@Autowired
	private BGoodsUnitMapper goodsUnitMapper;
	
    /**
     * 货品单位
     * @param params
     * @return
     */
	@Override
	public List<BGoodsUnit> selectGoodsUnitList(Map<String, Object> params) {
		return goodsUnitMapper.selectGoodsUnitList(params);
	}

	@Override
	public int deleteBatchIds(Integer[] ids) {
		return goodsUnitMapper.deleteBatchIds(ids);
	}
	
	/**
	 * 根据主键id查询物品单位的详情
	 * @param id
	 * @return
	 */
	@Override
	public BGoodsUnit selectByPrimaryKey(Integer id) {

		return goodsUnitMapper.selectByPrimaryKey(id);
	}
	
	/**
	 * 添加物品的单位
	 * @param goodsUnit
	 * @return
	 */
	@Override
	public int insert(BGoodsUnit goodsUnit) {
		goodsUnit.setCreateTime(new Date());
		goodsUnit.setIsDel(0);
		goodsUnit.setIsUsed(1);
		goodsUnit.setUpdateTime(new Date());
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMddHHmmss");
		String date=simpleDateFormat.format(new Date());
		goodsUnit.setUnitCode(date);
		return goodsUnitMapper.insertSelective(goodsUnit);
	}
	
	/**
	 * 根据主键id修改物品的单位
	 * @param goodsUnit
	 * @return
	 */
	@Override
	public int updateByPrimaryKeySelective(BGoodsUnit goodsUnit) {
		goodsUnit.setUpdateTime(new Date());
		return goodsUnitMapper.updateByPrimaryKeySelective(goodsUnit);
	}

	@Override
	public List<BGoodsUnit> selectIsUse(Integer[] ids) {
		return this.goodsUnitMapper.selectIsUse(ids);
	}

}
